Skip to content

fix(postgrest): reject strip_nulls combined with csv in either order - #1927

Merged
spydon merged 3 commits into
mainfrom
lukasklingsbo/sdk-2675-postgrest-strip_nullscsv-silently-drops-strip_nulls-while
Nov 3, 2026
Merged

spydon merged 3 commits into
mainfrom
lukasklingsbo/sdk-2675-postgrest-strip_nullscsv-silently-drops-strip_nulls-while

Conversation

@spydon

@spydon spydon commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes SDK-2675.

Problem

strip_nulls() refuses to run after csv(), but the opposite order was not checked. select("*").strip_nulls().csv() sent a plain text/csv request and silently dropped strip_nulls, because RequestConfig.send() only rewrites JSON Accept headers. strip_nulls().explain() had the same problem.

Change

  • New private RequestConfig._reject_strip_nulls(method) raises ValueError("strip_nulls() cannot be used with <method>()") when strip_nulls is set.
  • Both csv() overrides (the RPC builder in base_request_builder.py and the select builder in _async/, regenerated into _sync/) and the select builder's explain() call it before switching the Accept header.
  • The existing guard in strip_nulls() stays. It is still reachable through rpc(...).csv().strip_nulls(), since the RPC builder's csv() returns the same builder.
  • On the select builder, csv() returns a single request builder that has no strip_nulls(), so select("*").csv().strip_nulls() keeps failing with AttributeError (and is flagged by type checkers).

Behaviour change: strip_nulls().csv() and strip_nulls().explain() used to run and ignore strip_nulls. They now raise ValueError up front. Results did not change before, so callers relying on this only lose a no-op call.

Comparison with postgrest-js

postgrest-js throws in stripNulls() when Accept is already text/csv, but its csv() does not check shouldStripNulls, so stripNulls().csv() is silently ignored there as well. This PR keeps the matching csv().strip_nulls() behaviour and also rejects the reverse order instead of ignoring it.

Tests

tests/test_strip_nulls.py now runs against both the sync and async clients with a mock transport. It covers both call orders on the select and RPC builders, strip_nulls().explain(), plus plain csv() and plain strip_nulls() (array and single object) requests.

Self-review changes

A code review of the first revision led to:

  • Rejecting strip_nulls().explain(), which dropped the flag the same way as csv().
  • Moving the duplicated check into RequestConfig._reject_strip_nulls.
  • Merging the new tests into tests/test_strip_nulls.py instead of a second overlapping module, and running the existing header test on both clients.
  • Asserting that select().csv().strip_nulls() is rejected (AttributeError or ValueError) instead of locking in AttributeError only.
  • Making the helper private, after the capability matrix check flagged it as new public API.

@spydon
spydon requested a review from o-santi as a code owner November 3, 2026 12:55
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between de2c6fc and db3b19a.

Files selected for processing: 4
  • src/postgrest/src/postgrest/_async/request_builder.py
  • src/postgrest/src/postgrest/_sync/request_builder.py
  • src/postgrest/src/postgrest/base_request_builder.py
  • src/postgrest/tests/test_strip_nulls.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@spydon
spydon merged commit 0ed5b29 into main Nov 3, 2026
42 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-2675-postgrest-strip_nullscsv-silently-drops-strip_nulls-while branch November 3, 2026 13:08
spydon added a commit that referenced this pull request Nov 3, 2026
…pabase (#1931)

## What

Adds tests to the least-covered areas of supabase-py. No library code
changes.

Overall line coverage of library code (`--cov=src`, sync and async
trees, with local infra) goes from about 91.3% to 98.6%:

| Package   | Before | After |
| --------- | ------ | ----- |
| auth      | 89%    | 98%   |
| storage   | 91%    | 99%   |
| postgrest | 94%    | 99%   |
| realtime  | 92%    | 98%   |
| supabase  | 92%    | 98%   |
| functions | 99%    | 99%   |

## Tests added

All new tests mock HTTP with `httpx.MockTransport`, or mock the
websocket connection, so none of them need infra.

- `src/storage/tests/test_vectors.py`: every vector bucket, index and
vector operation (request paths, request bodies, omitted optional
fields, the `delete` batch size limit, API error parsing), plus
analytics bucket create, list and delete, and the missing-`pyiceberg`
error. Runs against both the sync and async clients.
- `src/auth/tests/_async/test_client_flows.py`: `initialize` from
implicit grant URLs (query and fragment, recovery, error redirects,
incomplete redirects), restoring and refreshing stored sessions, ID
token, SSO and OAuth sign-in (including PKCE), code exchange, identity
linking, reauthentication, MFA enroll, challenge, verify, unenroll and
list, the "requires a session" errors, API error mapping, and pagination
headers when listing OAuth clients.
- `src/auth/tests/_async/test_jwks_and_refresh.py`: `get_claims` with
real ES256 keys (JWKS caching and TTL, supplied JWKS, unknown key, empty
JWKS, forged signature), retry scheduling on network errors, and the
PKCE email change in `update_user`.
- `src/realtime/tests/test_client_channels.py` and
`test_channel_internals.py`: channel creation, replacement and removal,
`set_auth`, send buffering, presence state and diff handling, join reply
handling for postgres changes bindings, `join()`, the listen loop,
connect retries and backoff, and send and heartbeat close handling.
- `src/postgrest/tests/test_response_handling.py` and
`test_builder_edges.py`: error mapping for `select`, `single`,
`maybe_single` and `explain`, CSV and explain output, turning retries
off, retrying GET requests (writes aren't retried, and retries stop at
the limit), plus filter encodings (`fts` variants, `contained_by`, `ov`,
`contains`, `sl`), `match`, `offset`, `range`, `upsert` and the
deprecation warnings.
- `src/supabase/tests/_async/test_client.py`: falling back to the API
key when reading the session fails, and channel helper delegation.

The auth and supabase sync tests are generated with `make
<pkg>.build-sync`.

## Bugs found while writing these tests

Each was filed and fixed in its own PR. This branch first pinned them
with strict `xfail` tests, and those markers have been removed now that
every fix is on `main`.

- SDK-2667, #1919: `storage3.create_client()` always emitted the timeout
`DeprecationWarning`.
- SDK-2668, #1921: `MetadataConfiguration` rejected its Python field
name.
- SDK-2669, #1920: `set_session()` raised `IndexError` for an access
token that isn't a JWT.
- SDK-2670, #1923: implicit grant tokens in the URL fragment were
ignored.
- SDK-2671, #1922: `CodeExchangeParams` required `code_verifier`.
- SDK-1674, #1925: `remove_all_channels()` left the channels registered.
- SDK-2672, #1929: a join reply without matching `postgres_changes`
silently dropped every postgres callback.
- SDK-2673, #1928: `channel.join()` nested the config twice and left out
the access token.
- SDK-2674, #1926: `create_client()` didn't type-check the URL and key.
- SDK-2675, #1927: `strip_nulls()` combined with `csv()` was only
rejected in one call order.
- SDK-2676, #1930: removed the unused `_leave_open_topic()`.

Refs SDK-2666


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Tests**
* Expanded synchronous and asynchronous coverage for authentication
flows, session handling, JWT verification, refresh behavior, and
OAuth/PKCE scenarios.
* Added checks for database API requests, response and error handling,
retry behavior, realtime channels and presence, and vector storage
operations.
* Added client-level checks for authorization fallback and realtime
channel access.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant